################
#PSRM: Explaining Support for Redistribution: Social Insurance Systems and Fairness
#
#Observational Data
#Part II: Tax and Benefit Systems
#
#Verena Fetscher
#July 2022
####################

rm(list=ls())

##########################
#Load Data
##########################

#Import Social Insurance data
#https://stats.oecd.org/Index.aspx?DataSetCode=FIXINCLSA#
#Accessed 11-2017

Ins_single<-read.csv("TaxBen_OECD_single.csv", header = TRUE, sep = ",", quote = "\"",
               dec = ".")
names(Ins_single) <- c("COU","Country","FAM","Family.type","CHI","Number.of.children",
                       "ER1","First.earner","ER2","Second.earner","VAR","Variable",
                       "EMP","Employment.status","YEA","Year","Unit.Code","Unit",
                       "PowerCode.Code","PowerCode","Reference.Period.Code","Reference.Period",
                       "Value","Flag.Codes","Flags")
Ins_married<-read.csv("TaxBen_OECD_married67.csv", header = TRUE, sep = ",", quote = "\"",
                     dec = ".")
names(Ins_married) <- c("COU","Country","FAM","Family.type","CHI","Number.of.children",
                        "ER1","First.earner","ER2","Second.earner","VAR","Variable",
                        "EMP","Employment.status","YEA","Year","Unit.Code","Unit",
                        "PowerCode.Code", "PowerCode","Reference.Period.Code",
                        "Reference.Period","Value","Flag.Codes","Flags" )


##########################
#Extract indicators from data file for all countries
##########################

#single
single<-data.frame(Ins_single$Country[Ins_single$Employment.status=="Employed"&
                                             Ins_single$Variable=="Gross Income"],
  Ins_single$First.earner[Ins_single$Employment.status=="Employed"&
                                                Ins_single$Variable=="Gross Income"],
  Ins_single$Year[Ins_single$Employment.status=="Employed"&
                Ins_single$Variable=="Gross Income"],
  Ins_single$Value[Ins_single$Employment.status=="Employed"&
                Ins_single$Variable=="Gross Income"],
  Ins_single$Value[Ins_single$Employment.status=="Employed"&
                Ins_single$Variable=="Net Income"],
  Ins_single$Value[Ins_single$Employment.status=="Employed"&
                Ins_single$Variable=="Income Tax"],
  Ins_single$Value[Ins_single$Employment.status=="Unemployed"&
                Ins_single$Variable=="Net Income"])

names(single) <- c("Country","AW","Year","Gross","Net","Tax","Unemployment")
single$AW<-as.numeric(gsub("% of AW", "", single$AW))


#married
married<-data.frame(Ins_married$Country[Ins_married$Employment.status=="Employed"&
                                                     Ins_married$Variable=="Gross Income"],
                    Ins_married$First.earner[Ins_married$Employment.status=="Employed"&
                                               Ins_married$Variable=="Gross Income"],
                           Ins_married$Year[Ins_married$Employment.status=="Employed"&
                                             Ins_married$Variable=="Gross Income"],
                           Ins_married$Value[Ins_married$Employment.status=="Employed"&
                                              Ins_married$Variable=="Gross Income"],
                           Ins_married$Value[Ins_married$Employment.status=="Employed"&
                                              Ins_married$Variable=="Net Income"],
                           Ins_married$Value[Ins_married$Employment.status=="Employed"&
                                              Ins_married$Variable=="Income Tax"],
                           Ins_married$Value[Ins_married$Employment.status=="Unemployed"&
                                              Ins_married$Variable=="Net Income"])

names(married) <- c("Country","AW","Year","Gross","Net","Tax","Unemployment")
married$AW<-as.numeric(gsub("% of AW", "", married$AW))


#Remove full data file

rm(Ins_married,Ins_single)



#Replacement Rate

single$RR<-single$Unemployment/single$Net
married$RR<-married$Unemployment/married$Net

#Check
(married[married$Country=="Finland"&married$AW==148&married$Year==2014,])

 
#Plot
ggplot(married[married$Country=="Spain"&married$AW>=50&married$Year==2014,],
       aes(x = AW)) +
  geom_line(aes(y = Net/Gross,col="Net/Gross"))+
  geom_line(aes(y = Tax/Gross,col="Tax/Gross"))+
  geom_line(aes(y = Unemployment/Gross,col="Unemployment/Gross"))+
  scale_colour_manual("", 
                      breaks = c("Net/Gross", "Tax/Gross", "Unemployment/Gross"),
                      values = c("Net/Gross"="red", "Tax/Gross"="green","Unemployment/Gross"="blue"))+
  ggtitle("Austria 2014")+
  ylab("Proportion")+xlab("% of AW")+
  theme_minimal()+
  labs(caption="Source: OECD")+
  theme(axis.text=element_text(size=14),axis.title=element_text(size=16),
        legend.title=element_text(size=14) , legend.text=element_text(size=14))


single%>%
  group_by(Country,AW)%>%
  filter(AW>=50&AW<=200)%>%
  summarize(meanRR=mean(RR),
            meanNet=mean(Net),
            meanGross=mean(Gross),
            meanTax=mean(Tax),
            meanUnemployment=mean(Unemployment))%>%
  ggplot(aes(x=AW))+
  geom_line(aes(y = (meanNet/meanGross)*100,
                col="Net/Gross"))+
  geom_line(aes(y = (meanUnemployment/meanGross)*100,
                col="Unemployment/Gross"))+
  xlab("Average wage (in %)") +  
  ylab ("Share of gross income (in %)")+ 
  coord_cartesian(xlim=c(50,200), ylim=c(0,100))+
  scale_x_continuous(expand = c(0, 0)) + 
  scale_y_continuous(expand = c(0, 0)) +
  theme_bw()+
  theme(panel.border=element_blank(),
        legend.position="bottom",
        legend.text = element_text(size = 14),
        legend.title = element_blank(),
        axis.line=element_line(),
        axis.text=element_text(size=8),
        axis.title=element_text(size=14),
        strip.background =element_rect(fill=F,colour = "white"))+
  scale_color_manual(breaks = c("Net/Gross", "Unemployment/Gross"),
                     labels = c("Net income","Replacement rate"),
                     values=c("grey20", "grey70"))+
  facet_wrap(~factor(Country), nrow = 5)+ 
  theme(panel.spacing.x=unit(1, "lines"),
        panel.spacing.y=unit(0,"lines"),
        plot.margin = unit(c(0,0.3,0,0.3),"cm"))
  


##########################
#Calculation Benefit Progressivity
##########################

#Import data
load("DataFile_01_Income.Rda")


#Calculate area under curve using trpezoidal rule
AUC<-function(x,y){
  sum(diff(x)*rollmean(y,2))
}


#Progressive taxes are monotonically increasing in income, 
#benefits can be more or less progressive or regressive for different income categories.
#While tax function describes slope of income taxes very well,
#fares much less good in describing benefits.
#Set into relation area under curve of guaranteed benefits and equalized benefits for
#lowest 25% and highest 25%.



#Benefit concentration indicator function
prog<-function(x,y){
position_low<-y$AW[(x&y$AW>=50)&(x&y$AW<=75)]
rate_low<-y$RR[(x&y$AW>=50)&(x&y$AW<=75)]

#Area under Lorenz Curve
A<-AUC(position_low,rate_low)

#Area under Perfect Equality Line
B<-AUC(position_low,rep(mean(y$RR[(x&y$AW>=50)&(x&y$AW<=200)]),
                        length(rate_low)))

#Area under Perfect Equality-Lorenz Curve
diff_low<-(B-A)/B


###
position_high<-y$AW[(x&y$AW>=175)&(x&y$AW<=200)]
rate_high<-y$RR[(x&y$AW>=175)&(x&y$AW<=200)]

#Area under Lorenz Curve
A<-AUC(position_high,rate_high)

#Area under Perfect Equality Line
B<-AUC(position_high,rep(mean(y$RR[(x&y$AW>=50)&(x&y$AW<=200)]),
                        length(rate_high)))

#Area under Perfect Equality-Lorenz Curve
diff_high<-(B-A)/B

result<-(diff_high-diff_low)
return(result) 
}



##########################
#Generate data
##########################
#Loop through each country and each year

#Round 8 (2016)
#Round 7 (2014)
#Round 6 (2012)
#Round 5 (2010)
#Round 4 (2008)
#Round 3 (2006)
#Round 2 (2004)
#Round 1 (2002)


#all rounds
#chldhhe: Children in household
#1:Yes
#2:No

#round 1,2: 
#marital: Legal marital status
#1:Married
#5:Never married

#round 3,4:
#maritala: Legal marital status
#1:Married
#9:Never married and never in civil partnership


#Country loop
table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 


##########################
#Austria
##########################

country="AT"
country_="Austria"

#round 1:
round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])



table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 


##########################
#Belgium
##########################

country="BE"
country_="Belgium"

#round 1:
round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])



table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 


##########################
#Switzerland
##########################

country="CH"
country_="Switzerland"


#round 1:
round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])



table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 


##########################
#Germany
##########################

country="DE"
country_="Germany"

#round 1:
round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])




table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 


##########################
#Denmark
##########################

country="DK"
country_="Denmark"

#round1:
round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])




table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 


##########################
#Spain
##########################

country="ES"
country_="Spain"

#round 1:
round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])




table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 



##########################
#Finland
##########################

country="FI"
country_="Finland"

round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])



table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 



##########################
#France
##########################

country="FR"
country_="France"

#round 1
round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])



table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 



##########################
#United Kingdom
##########################

country="GB"
country_="United Kingdom"

round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])



table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 


##########################
#Ireland
##########################

country="IE"
country_="Ireland"

round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])



table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 



##########################
#Italy
##########################

country="IT"
country_="Italy"

#round1:
round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])



table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 


##########################
#Netherlands
##########################

country="NL"
country_="Netherlands"

#round 1:
round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])



table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 


##########################
#Norway
##########################

country="NO"
country_="Norway"

#round 1:
round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])



table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 



##########################
#Portugal
##########################

country="PT"
country_="Portugal"

round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])



table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

table(single$Country)
#Austria Belgium Denmark Finland France Germany Ireland Italy Netherlands         Norway 
#Portugal Spain Sweden Switzerland United Kingdom 



##########################
#Sweden
##########################

country="SE"
country_="Sweden"

round=1
x<-(single$Country==country_&single$Year==2002)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])


#round 2: 
round=2
x<-(single$Country==country_&single$Year==2004)

#single
progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Never married"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Never married"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$marital=="Married"&
                     data$chldhhe=="Yes"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$marital=="Married"&
                           data$chldhhe=="Yes"])



#round 3: 
round=3
x<-(single$Country==country_&single$Year==2006)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])


#round 4: 
round=4
x<-(single$Country==country_&single$Year==2008)

progressivity<-prog(x=x,y=single)
data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Never married and never in civil partnership"&
                     data$chldhhe=="No"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Never married and never in civil partnership"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritala=="Married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritala=="Married"&
                           data$chldhhe=="Yes"])



#round 5:
round=5
x<-(single$Country==country_&single$Year==2010)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 6:
round=6
x<-(single$Country==country_&single$Year==2012)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])

#round 7:
round=7
x<-(single$Country==country_&single$Year==2014)

progressivity<-prog(x=x,y=single)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="None of these (NEVER married or in legally registered civil"&
                     data$chldhhe=="No"]<-progressivity

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

#married
progressivity<-prog(x=x,y=married)

data$Progressivity[data$cntry==country&data$essround==round&
                     data$maritalb=="Legally married"&
                     data$chldhhe=="Yes"]<-progressivity
table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])
##########################



##########################
#Check
##########################

table(data$Progressivity[data$cntry==country&data$essround==7&
                           data$maritalb=="None of these (NEVER married or in legally registered civil"&
                           data$chldhhe=="No"])

table(data$Progressivity[data$cntry==country&data$essround==round&
                           data$maritalb=="Legally married"&
                           data$chldhhe=="Yes"])


group_by(data, 
         group = cntry) %>%
  summarise(meanProg = mean(Progressivity,na.rm=T))


names(data)[names(data)=="Progressivity"] <- "benefitsFamType"

group_by(data, 
         group = cntry) %>%
  summarise(meanProg = mean(benefitsFamType,na.rm=T))


table(data$benefitsFamType[data$cntry=="FI"])
##########################



##########################
#Generate averages
##########################

#generate data frame
df<-data.frame(table(single$Country,single$Year))
colnames(df)[1:2] <- c("country","year")


df$country[3]
for(i in 1:15){
  x<-(single$Country==df$country[i])
  #single
  progressivity<-prog(x=x,y=single)
  df$allRepl_Single[df$country==df$country[i]]<-progressivity
  
  #married
  progressivity<-prog(x=x,y=married)
  df$allRepl_Married[df$country==df$country[i]]<-progressivity
}





for(j in 2002:2014){
  for(i in 1:15) {
    x<-(single$Country==df$country[i]&single$Year==single$Year[j])
    #single
    progressivity<-prog(x,y=single)
    df$repl_Single[df$country==df$country[i]&df$year==single$Year[j]]<-progressivity
    
    #married
    progressivity<-prog(x=x,y=married)
    df$repl_Married[df$country==df$country[i]&df$year==single$Year[j]]<-progressivity
  }
}



df$country

df$cntry<-c("AT","BE","DK","FI","FR","DE","IE","IT","NL","NO","PT","ES","SE","CH","GB")

df<-within(df, rm(country))
df<-within(df, rm(Freq))

df$repl_Mean<-(df$repl_Married+df$repl_Single)/2
df$allRepl_Mean<-(df$allRepl_Single+df$allRepl_Married)/2


df %>%
  group_by(cntry) %>%                            
  summarize(mean = mean(allRepl_Mean))
##########################


#combied dot plot

df<-reshape(as.data.frame(df), varying=c("repl_Single","repl_Married","repl_Mean",
                                         "allRepl_Single","allRepl_Married",
                                         "allRepl_Mean"), 
            idvar = c("cntry","year"), 
            direction ="long", sep = "_")




#Match with data

data$meanProg[data$cntry=="AT"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="AT"])
data$meanProg[data$cntry=="BE"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="BE"])
data$meanProg[data$cntry=="CH"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="CH"])
data$meanProg[data$cntry=="DE"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="DE"])
data$meanProg[data$cntry=="DK"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="DK"])
data$meanProg[data$cntry=="ES"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="ES"])
data$meanProg[data$cntry=="FI"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="FI"])
data$meanProg[data$cntry=="FR"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="FR"])
data$meanProg[data$cntry=="GB"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="GB"])
data$meanProg[data$cntry=="IE"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="IE"])
data$meanProg[data$cntry=="IT"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="IT"])
data$meanProg[data$cntry=="NL"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="NL"])
data$meanProg[data$cntry=="NO"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="NO"])
data$meanProg[data$cntry=="PT"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="PT"])
data$meanProg[data$cntry=="SE"]<-mean(df$allRepl[df$time=="Mean"&df$cntry=="SE"])


data$Prog[data$cntry=="AT"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="AT"&df$year==2002]
data$Prog[data$cntry=="AT"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="AT"&df$year==2004]
data$Prog[data$cntry=="AT"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="AT"&df$year==2006]
data$Prog[data$cntry=="AT"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="AT"&df$year==2008]
data$Prog[data$cntry=="AT"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="AT"&df$year==2010]
data$Prog[data$cntry=="AT"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="AT"&df$year==2012]
data$Prog[data$cntry=="AT"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="AT"&df$year==2014]


data$Prog[data$cntry=="BE"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="BE"&df$year==2002]
data$Prog[data$cntry=="BE"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="BE"&df$year==2004]
data$Prog[data$cntry=="BE"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="BE"&df$year==2006]
data$Prog[data$cntry=="BE"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="BE"&df$year==2008]
data$Prog[data$cntry=="BE"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="BE"&df$year==2010]
data$Prog[data$cntry=="BE"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="BE"&df$year==2012]
data$Prog[data$cntry=="BE"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="BE"&df$year==2014]

data$Prog[data$cntry=="CH"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="CH"&df$year==2002]
data$Prog[data$cntry=="CH"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="CH"&df$year==2004]
data$Prog[data$cntry=="CH"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="CH"&df$year==2006]
data$Prog[data$cntry=="CH"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="CH"&df$year==2008]
data$Prog[data$cntry=="CH"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="CH"&df$year==2010]
data$Prog[data$cntry=="CH"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="CH"&df$year==2012]
data$Prog[data$cntry=="CH"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="CH"&df$year==2014]

data$Prog[data$cntry=="DE"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="DE"&df$year==2002]
data$Prog[data$cntry=="DE"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="DE"&df$year==2004]
data$Prog[data$cntry=="DE"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="DE"&df$year==2006]
data$Prog[data$cntry=="DE"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="DE"&df$year==2008]
data$Prog[data$cntry=="DE"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="DE"&df$year==2010]
data$Prog[data$cntry=="DE"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="DE"&df$year==2012]
data$Prog[data$cntry=="DE"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="DE"&df$year==2014]



data$Prog[data$cntry=="DK"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="DK"&df$year==2002]
data$Prog[data$cntry=="DK"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="DK"&df$year==2004]
data$Prog[data$cntry=="DK"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="DK"&df$year==2006]
data$Prog[data$cntry=="DK"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="DK"&df$year==2008]
data$Prog[data$cntry=="DK"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="DK"&df$year==2010]
data$Prog[data$cntry=="DK"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="DK"&df$year==2012]
data$Prog[data$cntry=="DK"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="DK"&df$year==2014]


data$Prog[data$cntry=="ES"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="ES"&df$year==2002]
data$Prog[data$cntry=="ES"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="ES"&df$year==2004]
data$Prog[data$cntry=="ES"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="ES"&df$year==2006]
data$Prog[data$cntry=="ES"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="ES"&df$year==2008]
data$Prog[data$cntry=="ES"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="ES"&df$year==2010]
data$Prog[data$cntry=="ES"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="ES"&df$year==2012]
data$Prog[data$cntry=="ES"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="ES"&df$year==2014]


data$Prog[data$cntry=="FI"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="FI"&df$year==2002]
data$Prog[data$cntry=="FI"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="FI"&df$year==2004]
data$Prog[data$cntry=="FI"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="FI"&df$year==2006]
data$Prog[data$cntry=="FI"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="FI"&df$year==2008]
data$Prog[data$cntry=="FI"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="FI"&df$year==2010]
data$Prog[data$cntry=="FI"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="FI"&df$year==2012]
data$Prog[data$cntry=="FI"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="FI"&df$year==2014]

data$Prog[data$cntry=="FR"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="FR"&df$year==2002]
data$Prog[data$cntry=="FR"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="FR"&df$year==2004]
data$Prog[data$cntry=="FR"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="FR"&df$year==2006]
data$Prog[data$cntry=="FR"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="FR"&df$year==2008]
data$Prog[data$cntry=="FR"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="FR"&df$year==2010]
data$Prog[data$cntry=="FR"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="FR"&df$year==2012]
data$Prog[data$cntry=="FR"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="FR"&df$year==2014]

data$Prog[data$cntry=="GB"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="GB"&df$year==2002]
data$Prog[data$cntry=="GB"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="GB"&df$year==2004]
data$Prog[data$cntry=="GB"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="GB"&df$year==2006]
data$Prog[data$cntry=="GB"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="GB"&df$year==2008]
data$Prog[data$cntry=="GB"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="GB"&df$year==2010]
data$Prog[data$cntry=="GB"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="GB"&df$year==2012]
data$Prog[data$cntry=="GB"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="GB"&df$year==2014]

data$Prog[data$cntry=="IE"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="IE"&df$year==2002]
data$Prog[data$cntry=="IE"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="IE"&df$year==2004]
data$Prog[data$cntry=="IE"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="IE"&df$year==2006]
data$Prog[data$cntry=="IE"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="IE"&df$year==2008]
data$Prog[data$cntry=="IE"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="IE"&df$year==2010]
data$Prog[data$cntry=="IE"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="IE"&df$year==2012]
data$Prog[data$cntry=="IE"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="IE"&df$year==2014]

data$Prog[data$cntry=="IT"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="IT"&df$year==2002]
data$Prog[data$cntry=="IT"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="IT"&df$year==2004]
data$Prog[data$cntry=="IT"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="IT"&df$year==2006]
data$Prog[data$cntry=="IT"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="IT"&df$year==2008]
data$Prog[data$cntry=="IT"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="IT"&df$year==2010]
data$Prog[data$cntry=="IT"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="IT"&df$year==2012]
data$Prog[data$cntry=="IT"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="IT"&df$year==2014]

data$Prog[data$cntry=="NL"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="NL"&df$year==2002]
data$Prog[data$cntry=="NL"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="NL"&df$year==2004]
data$Prog[data$cntry=="NL"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="NL"&df$year==2006]
data$Prog[data$cntry=="NL"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="NL"&df$year==2008]
data$Prog[data$cntry=="NL"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="NL"&df$year==2010]
data$Prog[data$cntry=="NL"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="NL"&df$year==2012]
data$Prog[data$cntry=="NL"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="NL"&df$year==2014]

data$Prog[data$cntry=="NO"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="NO"&df$year==2002]
data$Prog[data$cntry=="NO"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="NO"&df$year==2004]
data$Prog[data$cntry=="NO"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="NO"&df$year==2006]
data$Prog[data$cntry=="NO"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="NO"&df$year==2008]
data$Prog[data$cntry=="NO"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="NO"&df$year==2010]
data$Prog[data$cntry=="NO"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="NO"&df$year==2012]
data$Prog[data$cntry=="NO"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="NO"&df$year==2014]

data$Prog[data$cntry=="PT"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="PT"&df$year==2002]
data$Prog[data$cntry=="PT"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="PT"&df$year==2004]
data$Prog[data$cntry=="PT"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="PT"&df$year==2006]
data$Prog[data$cntry=="PT"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="PT"&df$year==2008]
data$Prog[data$cntry=="PT"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="PT"&df$year==2010]
data$Prog[data$cntry=="PT"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="PT"&df$year==2012]
data$Prog[data$cntry=="PT"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="PT"&df$year==2014]

data$Prog[data$cntry=="SE"&data$essround==1]<-
  df$repl[df$time=="Mean"&df$cntry=="SE"&df$year==2002]
data$Prog[data$cntry=="SE"&data$essround==2]<-
  df$repl[df$time=="Mean"&df$cntry=="SE"&df$year==2004]
data$Prog[data$cntry=="SE"&data$essround==3]<-
  df$repl[df$time=="Mean"&df$cntry=="SE"&df$year==2006]
data$Prog[data$cntry=="SE"&data$essround==4]<-
  df$repl[df$time=="Mean"&df$cntry=="SE"&df$year==2008]
data$Prog[data$cntry=="SE"&data$essround==5]<-
  df$repl[df$time=="Mean"&df$cntry=="SE"&df$year==2010]
data$Prog[data$cntry=="SE"&data$essround==6]<-
  df$repl[df$time=="Mean"&df$cntry=="SE"&df$year==2012]
data$Prog[data$cntry=="SE"&data$essround==7]<-
  df$repl[df$time=="Mean"&df$cntry=="SE"&df$year==2014]
table(df$cntry)


table(data$Prog[data$cntry=="SE"&data$essround==5])
table(data$meanProg[data$cntry=="SE"&data$essround==2])


names(data)[names(data)=="Prog"] <- "benefitsAvgYear"
names(data)[names(data)=="meanProg"] <- "benefitsAvg"
##########################


##########################
#Save data
##########################

#Combine ESS with benefit concentration indicator
save(data,file="DataFile_02_TaxBenefit.Rda")

#Beneift concentration indicator as separate file
save(df,file="Benefits.Rda")
##########################



